package com.hopital5.zhangyz.model;

import com.hopital5.zhangyz.vo.enums.PeopleSex;
import lombok.*;

import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;

@Entity
@Data
@EqualsAndHashCode(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class People extends BaseModelAndLongId {
    private String number;
    private String name;
    private PeopleSex peopleSex;
    @ManyToMany
    private List<Label> labels;
    @OneToMany(mappedBy = "people")
    private List<ActivityActivityItem> activityActivityItems;

    public People addLabel(Label label) {
        if (this.labels == null) {
            this.labels = new ArrayList<>();
        }
        this.labels.add(label);
        if (label.getPeoples() == null) {
            label.setPeoples(new ArrayList<>());
        }
        label.getPeoples().add(this);
        return this;
    }
}
